<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <%@ include file="../include/css.jsp" %>
</head>
<body>

<div class="content-wrapper">

    <!-- Main content -->
    <section class="content">

        <!-- Default box -->
        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title">编辑plugin</h3>

                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" id="backBtn">
                        <i class="fa fa-plus"></i> 返回列表
                    </button>
                </div>
            </div>
            <div class="box-body">
                <form action="/plugin/update/" accept-charset="UTF-8"  id="saveForm" method="post" enctype="multipart/form-data">
                    <div class="form-group">
                        <input type="hidden" name="id" value="${plugin.id}">
                        <label>名称</label>
                        <input type="text" name="name" value="${plugin.name}" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>类型</label>
                        <input type="text" name="type" value="${plugin.type}" class="form-control" >
                    </div>
                    <div class="form-group">
                        <label>运行环境</label>
                        <input type="text" name="runtimeEnvironment" value="${plugin.runtimeEnvironment}" class="form-control" >
                    </div>
                    <div class="form-group">
                        <label>关键字</label>
                        <input type="text" name="keyword" value="${plugin.keyword}" class="form-control" >
                    </div>
                    <div class="form-group">
                        <label>描述</label>
                        <input type="text" name="describe" value="${plugin.describe}" class="form-control" >
                    </div>
                    <div class="form-group">
                        <label>关联用户</label>
                        <select name="userId" class="form-control">
                            <c:forEach items="${list}" var="user">
                                <c:choose>
                                    <c:when test="${plugin.user.id==user.id}">
                                        <option selected = "selected" value="${user.id}">${user.name}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${user.id}">${user.name}</option>
                                    </c:otherwise>
                                </c:choose>
                                <%--<option value="${user.id}">${user.name}</option>--%>
                            </c:forEach>
                        </select>
                    </div>
                </form>
            </div>
            <!-- /.box-body -->
            <div class="box-footer">
                <button class="btn btn-primary" id="saveBtn">保存</button>
            </div>
        </div>
        <!-- /.box -->

    </section>
    <!-- /.content -->
</div>

<script
        src="https://code.jquery.com/jquery-2.2.4.min.js"
        integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
        crossorigin="anonymous"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<%@ include file="../include/js.jsp"%>
<script>

    $(function () {

        $("#backBtn").click(function () {
            window.location.href="/plugin/all"
        });


        $("#saveBtn").click(function () {
            $("#saveForm").submit();
        });

        $("#saveForm").validate({
            errorClass : 'text-danger',
            errorElement : 'span',
            rules : {
                name :{
                    "required" : true
                },
                type : {
                    "required" : true
                },
                runtimeEnvironment : {
                    "required" : true
                },
                keyword : {
                    "required" : true
                },
                describe : {
                    "required" : true
                },
                userId : {
                    "required" : true
                }


            },
            messages :{
                name :{
                    "required" : "必填项！"
                },
                type :{
                    "required" : "必填项！"
                },
                runtimeEnvironment :{
                    "required" : "必填项！"
                },
                keyword :{
                    "required" : "必填项！"
                },
                describe :{
                    "required" : "必填项！"
                },
                userId :{
                    "required" : "必填项！"
                }
            }

        })

    })
</script>
</body>
</html>

